<?php include('./templete/public/head.php') ?>

<body>

<hr class="bgcolor"/>
<!--发布金点子-->
<div class="fabu-main fabu-idea-main">
    <div class="main-content">
        <div class="c-list">
            <form id="myform">
                <ul class="comm-table-view">
                    <li class="table-view-cell">
                        <a>
                            <span class="title">标题</span>
                            <span class="line">|</span>
                            <span class="input"><input type="text" name="title" id="title" value="<?php echo $rows['title']?>" placeholder="标题不少于三个字符"/></span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>
                    <li class="table-view-cell">
                        <a>
                            <span class="title">部门</span>
                            <span class="line">|</span>
                            <span class="input" id="showDepartPicker">
                            <input type="text" name="department" id="departName" value="<?php echo $rows['department']?>" placeholder="" readonly/></span>
                            <input type="hidden" name="departid" id="departid" value="<?php echo $rows['departid']?>" placeholder="" readonly/></span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>
                    <li class="table-view-cell">
                        <a>
                            <span class="title">请选择分类</span>
                            <span class="line">|</span>
                            <span class="input" id="showClassPicker">
                                <input type="text" name="question_classfy" id="className" value="<?php echo $rows['question_classfy']?>" placeholder="" readonly/>
                                <input type="hidden" name="question_classfyid" id="question_classfyid" value="<?php echo $rows['question_classfyid']?>" placeholder="" readonly/>
                            </span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>
                    <li class="table-view-cell">
                        <a>
                            <span class="title">完成方式</span>
                            <span class="line">|</span>
                            <span class="input" id="showModePicker">
                                <input type="text"  id="modeName" value="" placeholder="" readonly/></span>
                            <input type="hidden" name="complete_type" id="complete_type" value="<?php echo $rows['complete_type']?>"  readonly/></span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>
                    <li class="table-view-cell partner"  style="display: none">
                        <a>
                            <span class="title">合作人员</span>
                            <span class="line">|</span>
                            <span class="input">
                                <input type="text" name="partners" id="hezuoPeople" value="<?php echo $rows['partners']?>"  readonly/>
                                <input type="hidden" name="partners_id" id="partners_id" value="<?php echo $rows['partners_id']?>"  readonly/>
                            </span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>


                    <li class="table-view-cell table-view-cell2">
                        <a>
                            <span>存在问题</span>
                            <div class="fabu-text">
                                <textarea name="problem_content"><?php echo $rows['problem_content']?></textarea>
                            </div>
                            <div class="fabu-upload">
                                <img src="_images/icon/upload.jpg" class="showPopover _file_upload"/>
                                <?php if($rows['_problem_file_url']){?>
                                    <p onclick="donload_file('<?php echo $rows['_problem_file_url']?>')">下载附件</p>
                                <?php }?>
                            </div>
                            <button type="button" class="layui-btn _file_uploads"  style="display: none">
                            </button>
                            <input type="hidden" name="_problem_file_url" id="_problem_file_url" class="_file_url" value="<?php echo $rows['_problem_file_url']?>">
                        </a>
                    </li>
                    <li class="table-view-cell table-view-cell2">
                        <a>
                            <span>解决的方法</span>
                            <div class="fabu-text">
                                <textarea name="solution_content"><?php echo $rows['solution_content']?></textarea>
                            </div>
                            <div class="fabu-upload">
                                <img src="_images/icon/upload.jpg" class="showPopover _file_upload"/>
                                <?php if($rows['_solution_file_url']){?>
                                    <p onclick="donload_file('<?php echo $rows['_solution_file_url']?>')">下载附件</p>
                                <?php }?>
                            </div>
                            <button type="button" class="layui-btn _file_uploads"  style="display: none">
                            </button>
                            <input type="hidden" name="_solution_file_url" id="_solution_file_url" class="_file_url" value="<?php echo $rows['_solution_file_url']?>" >
                        </a>
                    </li>
                    <li class="table-view-cell">
                        <a>
                            <span class="title">是否形成知识产权</span>
                            <span class="line">|</span>
                            <span class="input" id="is_right_doc">
                                <input type="text" id="isRight" value="" placeholder="" readonly/></span>
                            <input type="hidden" name="is_right" id="is_right" value="" readonly/></span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>
                    <li class="table-view-cell right_type_li" style="display: none">
                        <a>
                            <span class="title">产权类型</span>
                            <span class="line">|</span>
                            <span class="input" id="right_type_doc">
                                <input type="text" id="rightType" value="" placeholder="" readonly/></span>
                            <input type="hidden" name="right_type" id="right_type" value="" readonly/></span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>
                </ul>
                <input type="hidden" name="id" value="<?php echo $rows['id']?>">
            </form>
            <div class="comm-btn comm-btn2 fabu-btn">
                <span class="color1 publish">提交</span>
                <!--                <span class="color2">越级提交</span>-->
            </div>
        </div>
    </div>
</div>

</body>
<script src="_js/plug/mui.picker.all.js"></script>
<?php include('./templete/public/script.php')?>
<script>
    $('.publish').click(function () {
        var param = $('#myform').serializeArray();
        if(!$('#title').val()){
            layer.msg('请输入标题');
            return false;
        }
        if(!$('#departid').val()){
            layer.msg('请选择部门');
            return false;
        }
        /*
        if(!$('#question_classfyid').val()){
            layer.msg('请选择问题分类');
            return false;
        }
        if(!$('#complete_type').val()){
            layer.msg('请选择完成方式');
            return false;
        }

         */
        layer.msg('信息提交中',{time:60000,icon: 16,shade: 0.3});
        $.ajax({
            url:'<?php echo url("again")?>',
            data:param,
            type: 'post',
            success:function (data) {
                if(data.code ==2){
                    layer.msg(data.msg);
                    return false;
                }
                if(data.code==1){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        location.href='<?php echo url('jdz/detail',['id'=>$rows['id']])?>'
                    },1000)
                }else{
                    layer.msg('发布失败，请联系管理员');
                    setTimeout(function () {
                        layer.closeAll();
                    },1000)
                }

            }
        })
    });
    $('._file_upload').click(function () {
        var oThis = $(this).parent().next();
        console.log(oThis);
        oThis.click();
    });
    var subinvman_sel3 = $("#showClassPicker");//请选择分类
    var subinvman_sel4 = $("#showModePicker");//完成方式
    var subinvman_sel5 = $("#is_right_doc");//知识产权
    var subinvman_sel6 = $("#right_type_doc");//知识产权类型

    if (subinvman_sel3) {
        var picker3 = new mui.PopPicker();
        picker3.setData([{value: '1', text: '产品质量'}, {value: '2', text: '产品成本'}, {value: '3', text: '产品性能'}
            ,{value: '4', text: '标准作业程序'}, {value: '5', text: '工作流程'}, {value: '6', text: '设备'}
            ,{value: '7', text: '设施'}, {value: '8', text: '物料储运'}, {value: '9', text: '环境、健康、安全'}
            ,{value: '10', text: '食堂及伙食'}, {value: '11', text: '其他'}
        ]);
        document.querySelector("#showClassPicker").addEventListener("tap", function () {
            picker3.show(function (items) {
                $("#className").val(items[0].text);
                $("#question_classfyid").val(items[0].value);

            });
        });
    }

    if (subinvman_sel4) {
        var picker4 = new mui.PopPicker();
        //picker4.setData([{value: '1', text: '我提你改'}, {value: '2', text: '自提自改'}, {value: '3', text: '寻求合作'}]);
		picker4.setData([{value: '1', text: '我提你改'}, {value: '3', text: '寻求合作'}]);
        document.querySelector("#showModePicker").addEventListener("tap", function () {
            picker4.show(function (items) {
                console.log(items[0].text)
                $("#modeName").val(items[0].text);
                $("#complete_type").val(items[0].value);
                if (items[0].value == 3) {
                    $('.partner').show();
                } else {
                    $('.partner').hide();
                }

            });
        });
    }

    if (subinvman_sel5) {
        var picker5 = new mui.PopPicker();
        picker5.setData([{value: '2', text: '否'}, {value: '1', text: '是'}]);
        document.querySelector("#is_right_doc").addEventListener("tap", function () {
            picker5.show(function (items) {
                console.log(items[0].text)
                $("#isRight").val(items[0].text);
                $("#is_right").val(items[0].value);
                if (items[0].value == 1) {
                    $('.right_type_li').show();
                } else {
                    $('.partner').hide();
                    $('#rightType').val('');
                    $('#right_type').val('');
                }
            });
        });
    }
    if (subinvman_sel6) {
        var picker6 = new mui.PopPicker();
        picker6.setData([{value: '1', text: '专利'}, {value: '2', text: '商业秘密'}]);
        document.querySelector("#right_type_doc").addEventListener("tap", function () {
            picker6.show(function (items) {
                console.log(items[0].text)
                $("#rightType").val(items[0].text);
                $("#right_type").val(items[0].value);
            });
        });
    }

    $("#hezuoPeople").on("click", function () {
        var partners_id = $('#partners_id').val();
        _partners_id = partners_id.split(',');
        select_entercontact('multi','user',_partners_id,'user');
    });
    $('#showDepartPicker').on('click',function () {
        select_entercontact('single','department',[],'department');
    })

    function select_entercontact(mode,type,_partners_id,cases){
        wx.invoke("selectEnterpriseContact", {
                "fromDepartmentId": -1,// 必填，表示打开的通讯录从指定的部门开始展示，-1表示自己所在部门开始, 0表示从最上层开始
                "mode": mode,// 必填，选择模式，single表示单选，multi表示多选
                "type": [type],// 必填，选择限制类型，指定department、user中的一个或者多个
                //"selectedDepartmentIds": ["2","3"],// 非必填，已选部门ID列表。用于多次选人时可重入，single模式下请勿填入多个id
                "selectedUserIds": _partners_id// 非必填，已选用户ID列表。用于多次选人时可重入，single模式下请勿填入多个id
            },function(res){
                if (res.err_msg == "selectEnterpriseContact:ok")
                {
                    if(typeof res.result == 'string')
                    {
                        res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容，需要开发者额外判断result类型以保证在各个终端的兼容性
                    }
                    var selectedUserList = res.result.userList; // 已选的成员列表
                    var userId=Array();
                    var userName=Array();
                    var userAvatar=Array();
                    var departmentId =Array();
                    var departemntName =Array();
                    var selectedDepartmentList = res.result.departmentList;// 已选的部门列表
                    for (var i = 0; i < selectedDepartmentList.length; i++)
                    {
                        var department = selectedDepartmentList[i];
                        departmentId[i] = department.id;// 已选的单个部门ID
                        departemntName[i] = department.name;// 已选的单个部门名称
                    }
                    for (var i = 0; i < selectedUserList.length; i++)
                    {
                        var user = selectedUserList[i];
                        userId[i] = user.id; // 已选的单个成员ID
                        userName[i] = user.name;// 已选的单个成员名称
                        userAvatar[i]= user.avatar;// 已选的单个成员头像
                    }
                    if(cases=='user') {
                        $("#hezuoPeople").val(userName);
                        $("#partners_id").val(userId);
                    }
                    if(cases == 'department'){
                        $('#departName').val(departemntName);
                        $('#departid').val(departmentId);
                    }
                }
            }
        );
    }

    function donload_file(file_url) {
        window.location=file_url;
    }
</script>

</html>